import type { IQuery, IResData } from '@/api/indexTypes';
import { org, root, sys } from '../apiRoot';
import { defHttp } from '@/utils/http';
import type {
  ActivityOrderDetailResult,
  CreateOrderData,
  CreateOrderResult,
  CreateSuborderResult,
  GetContactInformationResult,
  MembershipOrderDetailsResult,
  MyOrderListData,
  MyOrderListReslut,
  ToPayData,
  ToPayResult,
  UnlockOrderDetailResult,
} from './types';
import { OrderStateEnum, OrderTypeEnum } from '@/enums/orderEnum';

export const Api = {
  memberContactsCreateSuborder: root + 'member-contacts/createSuborder',
  memberContactsCreateOrder: root + 'member-contacts/createOrder',
  toPay: root + 'pay/toPay',
  getByIdOrderDetail: root + 'app-user-order/getByIdOrderDetail',
  getContactInformation: org + 'businessCard/getContactInformation',
  cancellOrder: root + 'app-user-order/cancellOrder',
  myOrderList: root + 'app-user-order/pageList',
};

/**
 * @description 1.创建人脉子订单
 * @date 22/02/2023
 * @export
 * @param {{ orderType: OrderTypeEnum, memberLeadingId: number }} data
 */
export function memberContactsCreateSuborder(data: CreateOrderData) {
  return defHttp.post<CreateSuborderResult>({
    url: Api.memberContactsCreateSuborder,
    data,
  });
}

/**
 * @description 创建订单
 * @date 23/02/2023
 * @export
 * @param {CreateOrderData} data
 */
export function memberContactsCreateOrder(data: { remark?: string } & CreateOrderData) {
  return defHttp.post<CreateOrderResult>({
    url: Api.memberContactsCreateOrder,
    data,
  });
}

/**
 * @description 获取支付Api所需参数
 * @date 23/02/2023
 * @export
 * @param {ToPayData} data
 */
export function toPay(data: ToPayData) {
  return defHttp.post<ToPayResult>({
    url: Api.toPay,
    data,
  });
}

/**
 * @description 获取解锁订单详情
 * @date 23/02/2023
 * @export
 * @param {number} orderId
 */
export function getunlockOrderDetail(orderId: string) {
  return defHttp.get<UnlockOrderDetailResult>({
    url: Api.getByIdOrderDetail + `/${orderId}`,
  });
}

/**
 * @description 获取申请人联系方式
 * @date 24/02/2023
 * @export
 * @param {number} memberLeadingId
 */
export function getContactInformation(memberLeadingId: number) {
  return defHttp.get<GetContactInformationResult>({
    url: Api.getContactInformation + `/${memberLeadingId}`,
  });
}

/**
 * @description 获取订单详情-会费
 * @date 23/02/2023
 * @export
 */
export function getMembershipOrder(orderCode: string) {
  return defHttp.get<MembershipOrderDetailsResult>({
    url: Api.getByIdOrderDetail + `/${orderCode}`,
  });
}

/**
 * @description 获取活动订单详情
 * @date 01/07/2024
 * @export
 * @param {string} orderCode
 */
export function getActivityOrderDetail(orderCode: string) {
  return defHttp.get<ActivityOrderDetailResult>({
    url: Api.getByIdOrderDetail + `/${orderCode}`,
  })
}
/**
 * @description 取消订单
 * @date 24/02/2023
 * @export
 * @param {string} orderId 订单ID
 */
export function cancellOrder(orderId: number) {
  return defHttp.get({
    url: Api.cancellOrder + `/${orderId}`,
  });
}

/**
 * @description 我的订单列表
 * @date 28/02/2023
 * @export
 * @param {IQuery} data
 */
export function myOrderList(data: MyOrderListData) {
  return defHttp.post<IResData<MyOrderListReslut>>({
    url: Api.myOrderList,
    data,
  });
}

/**
 * @description 订单支付回调, 测试环境所用
 * @date 28/02/2023
 * @export
 * @param {string} orderCode
 */
export function orderPayCallback(orderCode: string) {
  return defHttp.post({
    url: root + 'app-user-order/orderCallback' + `/${orderCode}`,
  });
}
